package com.thread5.mulity;

public class MulityThread {
	static int count=0;
	static boolean isLock=true;
	static boolean isLock2=true;
	Object mutex=new Object();
	public static void main(String[] args) {
		
		
		Buy buy=new MulityThread().new Buy();
		Sell sell=new MulityThread().new Sell();
		buy.setName("buy");
		buy.start();
		sell.setName("sell");
		sell.start();
	}
	
	class Buy extends Thread{
		@Override
		public  void run() {
			super.run();
			
			while(count<100){
				if(isLock){
				count++;
				if(count==30){
					isLock=false;
				}
				System.out.println(Buy.this.getName()+",count==="+count);
				try {
					Thread.sleep(200);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			}
			
		}
		
	}

	private void increate(){
		count++;
	}


	class Sell extends Thread{
		@Override
		public void run() {
			super.run();
			synchronized (mutex) {
			
				while(count<100){
					if(isLock2){
					count++;
					if(count==50){
						isLock2=false;
					}
					System.out.println(Sell.this.getName()+",count==="+count);
					try {
						Thread.sleep(200);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}}
			
			
		}
		
	}

}
